﻿Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports CQRSAzure.Tools
Imports System.ComponentModel

<TestClass()>
Public Class AggregateModelUnitTest

    <TestMethod()>
    Public Sub Constructor_Empty_TestMethod()

        Dim testObj As New AggregateModel()
        Assert.IsNotNull(testObj)

    End Sub

    <TestMethod>
    Public Sub Constructor_Name_TestMethod()

        Dim testObj As New AggregateModel("InitialName")
        Assert.IsNotNull(testObj)

    End Sub

    <TestMethod>
    Public Sub Name_RoundTrip_TestMethod()

        Dim expected As String = "ExpectedName"
        Dim actual As String = "NotSet"

        Dim testObj As New AggregateModel(expected)
        actual = testObj.Name

        Assert.AreEqual(expected, actual)

    End Sub

    <TestMethod>
    Public Sub Keyname_ChangeNotification_TestMethod()

        Dim expected As String = "KeyName"
        Dim actual As String = "Not Set"

        Dim testObj As New AggregateModel("TestObject")


        AddHandler testObj.PropertyChanged, New PropertyChangedEventHandler(
            Sub(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
                actual = e.PropertyName
            End Sub
            )

        testObj.KeyName = "My key"

        testObj = Nothing

        Assert.AreEqual(expected, actual)


    End Sub

    <TestMethod>
    Public Sub KeyType_ChangeNotification_TestMethod()

        Dim expected As String = "KeyType"
        Dim actual As String = "Not Set"

        Dim testObj As New AggregateModel("TestObject")


        AddHandler testObj.PropertyChanged, New PropertyChangedEventHandler(
            Sub(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
                actual = e.PropertyName
            End Sub
            )

        testObj.KeyType = KeyDataType.DataTypeInteger

        testObj = Nothing

        Assert.AreEqual(expected, actual)


    End Sub

    <TestMethod>
    Public Sub EventAdded_RoundTrip_TestMethod()

        Dim expected As New EventModel("MyEvent")
        Dim actual As EventModel

        Dim testObj As New AggregateModel("My Aggregeate")
        testObj.AddNewEvent(expected.Name)
        actual = testObj.Events(expected.Name)

        Assert.AreEqual(expected, actual)

    End Sub

    <TestMethod>
    Public Sub EventAdded_Event_TestMethod()

        Dim expected As String = "MyEvent"
        Dim actual As String

        Dim testObj As New AggregateModel("My Aggregeate")

        AddHandler testObj.EventModelAdded, New AggregateModel.EventModelAddedEventHandler(
            Sub(ByVal sender As Object, ByVal e As EventModelEventArgs)
                actual = e.EventName
            End Sub
            )

        testObj.AddNewEvent(expected)

        testObj = Nothing

        Assert.AreEqual(expected, actual)

    End Sub

End Class

<TestClass>
Public Class AggregateEventArgsUnitTest

    <TestMethod>
    Public Sub Constructor_TestMethod()

        Dim testObj As New AggregateModelEventArgs("AffectedModel")
        Assert.IsNotNull(testObj)

    End Sub

    <TestMethod>
    Public Sub AffectedName_RoundTrip_TestMethod()

        Dim expected As String = "ExpectedName"
        Dim actual As String = "Not Set"

        Dim testObj As New EventModelEventArgs(expected)

        actual = testObj.EventName

        Assert.AreEqual(expected, actual)

    End Sub

End Class